﻿// -------------------------------------------------------------------------
//    @FileName         :    NFSnsCommonModule.cpp
//    @Author           :    gaoyi
//    @Date             :    2025-03-26
//    @Email			:    445267987@qq.com
//    @Module           :    NFSnsCommonModule
//
// -------------------------------------------------------------------------

#include "NFSnsCommonModule.h"

NFSnsCommonModule::NFSnsCommonModule(NFIPluginManager* p): NFMMODynamicModule(p)
{
}

NFSnsCommonModule::~NFSnsCommonModule()
{
}

int NFSnsCommonModule::Awake()
{
    return 0;
}

int NFSnsCommonModule::Tick()
{
    return 0;
}

int NFSnsCommonModule::OnDynamicPlugin()
{
    return 0;
}

int NFSnsCommonModule::OnExecute(uint32_t serverType, uint32_t nEventID, uint32_t bySrcType, uint64_t nSrcID, const google::protobuf::Message* pMessage)
{
    return 0;
}

int NFSnsCommonModule::OnHandleClientMessage(uint64_t unLinkId, NFDataPackage& packet)
{
    if (!m_pObjPluginManager->IsInited(NF_ST_SNS_SERVER))
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Center Server not inited, drop client msg:{}", packet.ToString());
        return -1;
    }

    if (m_pObjPluginManager->IsServerStopping())
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Center Server is Stopping, drop client msg:{}", packet.ToString());
        return -1;
    }


    switch (packet.nMsgId)
    {
        default:
        {
            NFLogError(NF_LOG_DEFAULT, 0, "Client MsgId:{} Register, But Not Handle, Package:{}", packet.nMsgId, packet.ToString());
            break;
        }
    }
    return 0;
}

int NFSnsCommonModule::OnHandleServerMessage(uint64_t unLinkId, NFDataPackage& packet)
{
    if (!m_pObjPluginManager->IsInited(NF_ST_SNS_SERVER))
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Sns Server not inited, drop client msg:{}", packet.ToString());
        return -1;
    }

    if (m_pObjPluginManager->IsServerStopping())
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Sns Server is Stopping, drop client msg:{}", packet.ToString());
        return -1;
    }

    switch (packet.nMsgId)
    {
        default:
        {
            NFLogError(NF_LOG_DEFAULT, 0, "Server MsgId:{} Register, But Not Handle, Package:{}", packet.nMsgId, packet.ToString());
            break;
        }
    }
    return 0;
}